package cn.zust.itcost.service.impl;

import cn.zust.itcost.entity.Enterprise;
import cn.zust.itcost.mapper.EnterpriseMapper;
import cn.zust.itcost.service.EnterpriseService;
import cn.zust.itcost.service.PredictService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper, Enterprise> implements EnterpriseService {

    @Autowired
    private PredictService predictService;

    @Autowired
    private EnterpriseMapper enterpriseMapper;

    /**
     * trend2
     * @param firstDayOfMonth
     * @param lastDayOfMonth
     * @param needJob
     * @return
     */
    @Override
    public int getUserCountByMonthRangeandNeedJob(LocalDate firstDayOfMonth, LocalDate lastDayOfMonth, String needJob) {
        int count = 0;
        QueryWrapper<Enterprise> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("settime", firstDayOfMonth, lastDayOfMonth)
                .eq("need", needJob);
        List<Enterprise> enterpriseList = enterpriseMapper.selectList(queryWrapper);

        for (Enterprise enterprise : enterpriseList) {
            count += enterprise.getCount();
        }

        return count;
    }

}
